package com.dgut.ibeacon.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public ModelAndView Handler(Exception e) {
        e.printStackTrace();
        ModelAndView mv = new ModelAndView();
        mv.addObject("exception", e);
        mv.setViewName("/error/error");
        return mv;

    }

    @ExceptionHandler(value = UnauthorizedException.class)
    public ModelAndView processUnauthenticatedException(HttpServletRequest request, UnauthorizedException e) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("exception", e);
        mv.setViewName("/error/unauth");
        return mv;
    }


}
